﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 控制台数据流输出
{
    class Program
    {
        static void Main(string[] args)
        {

            //获取控制台数据 cc = new 获取控制台数据();
            //cc.Start();
            //输出
            //cc.Test();

            ShowTcpStatistics(System.Net.NetworkInformation.NetworkInterfaceComponent.IPv4 );

            //从网络流输出
            ConsoleHelper.NetWorkStreamWriter.WriteLine("控制台网络流输出准备就绪...");
            int i = 0;
            while (true) {
                Console.WriteLine("按任意键输出下一行.."+(i++));
                Console.ReadLine();
            }
            Console.Read();

             

        }
        /// <summary>
        /// 下面的代码示例显示指定地址族的 TCP 统计信息。
        /// </summary>
        /// <param name="version"></param>
        public static void ShowTcpStatistics(System.Net.NetworkInformation.NetworkInterfaceComponent version)
        {
            System.Net.NetworkInformation.IPGlobalProperties properties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
            System.Net.NetworkInformation.TcpStatistics tcpstat = null;
            Console.WriteLine("");
            switch (version)
            {
                case System.Net.NetworkInformation.NetworkInterfaceComponent.IPv4:
                    tcpstat = properties.GetTcpIPv4Statistics();
                    Console.WriteLine("TCP/IPv4 Statistics:");
                    break;
                case System.Net.NetworkInformation.NetworkInterfaceComponent.IPv6:
                    tcpstat = properties.GetTcpIPv6Statistics();
                    Console.WriteLine("TCP/IPv6 Statistics:");
                    break;
                default:
                    throw new ArgumentException("version");
                //    break;
            }
            Console.WriteLine("  Minimum Transmission Timeout............. : {0}",
                tcpstat.MinimumTransmissionTimeout);
            Console.WriteLine("  Maximum Transmission Timeout............. : {0}",
                tcpstat.MaximumTransmissionTimeout);

            Console.WriteLine("  Connection Data:");
            Console.WriteLine("      Current  ............................ : {0}",
            tcpstat.CurrentConnections);
            Console.WriteLine("      Cumulative .......................... : {0}",
                tcpstat.CumulativeConnections);
            Console.WriteLine("      Initiated ........................... : {0}",
                tcpstat.ConnectionsInitiated);
            Console.WriteLine("      Accepted ............................ : {0}",
                tcpstat.ConnectionsAccepted);
            Console.WriteLine("      Failed Attempts ..................... : {0}",
                tcpstat.FailedConnectionAttempts);
            Console.WriteLine("      Reset ............................... : {0}",
                tcpstat.ResetConnections);

            Console.WriteLine("");
            Console.WriteLine("  Segment Data:");
            Console.WriteLine("      Received  ........................... : {0}",
                tcpstat.SegmentsReceived);
            Console.WriteLine("      Sent ................................ : {0}",
                tcpstat.SegmentsSent);
            Console.WriteLine("      Retransmitted ....................... : {0}",
                tcpstat.SegmentsResent);

            Console.WriteLine("");
        }
    }
}
